package com.zmj.sy.mom.srv.aps.utils;

import com.zmj.sy.mom.srv.aps.bean.vo.base.BaseResVo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
public class PageUtils<T> extends BaseResVo {
    @ApiModelProperty(value = "当前页码")
    private long pageNo;
    @ApiModelProperty(value = "页面大小")
    private long pageSize;
    @ApiModelProperty(value = "总页数")
    private long pageCount;
    @ApiModelProperty(value = "总条数")
    private long total;
    @ApiModelProperty(value = "每页的数据集合")
    private List<T> data;


    public PageUtils(long pageIndex, long pageSize, List<T> records) {
        this.pageNo = pageIndex;
        this.pageSize = pageSize;
        this.total = records.size();
        this.pageCount = (total % pageSize == 0) ? (total / pageSize) : (total / pageSize + 1);
        Long startPageNum = (pageNo - 1) * pageSize;
        List<T> newList = new ArrayList<>();
        for (int i = 0; i + startPageNum < records.size() && i < pageSize; i++) {
            newList.add(records.get((int) (i + startPageNum)));
        }
        this.data = newList;
    }

    public PageUtils() {
        this.pageCount = (total % pageSize == 0) ? (total / pageSize) : (total / pageSize + 1);
    }

    public long getPageNo() {
        return pageNo;
    }

    public void setPageNo(long pageNo) {
        this.pageNo = pageNo;
    }

    public long getPageSize() {
        return pageSize;
    }

    public void setPageSize(long pageSize) {
        this.pageSize = pageSize;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public long getPageCount() {
        return pageCount;
    }

    public void setPageCount(long pageCount) {
        this.pageCount = pageCount;
    }

    public List<T> getRecords() {
        return data;
    }

    public void setRecords(List<T> records) {
        this.data = records;
    }
}




